﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Ccit.OA.MsQuestion;

namespace Ccit.OA.Question
{
    public partial class qst_manage_logView : Ccit.Utils.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ViewState["Query"] = "";
                _hidsRecId.Value = (null != Request.QueryString["QId"]) ? Request.QueryString["QId"].ToString() : "";
                _hidUserId.Value = (null != Request.QueryString["userId"]) ? Request.QueryString["userId"].ToString() : "";
                if (_hidUserId.Value == "")
                {
                    tdMessage.Attributes["style"] = "display:none";
                }
            }
            InitPage();
            DataBindeTable();
        }
        private void InitPage()
        {
            if (_hidsRecId.Value != "")
            {
                QuestionBLL Bll = new QuestionBLL();
                MsQuestionMes msMes = Bll.GetQuestions(_hidsRecId.Value.ToString());
                if (msMes != null)
                {
                    lblTitle.Text = (msMes.title!="")?msMes.title:"&nbsp;";
                    lblEndTime.Text = (msMes.endtime!="")?msMes.endtime:"&nbsp;";
                    lblExplain.Text = (msMes.explain!="")?msMes.explain:"&nbsp;";
                    lblType.Text = (msMes.type == "0") ? "匿名" : "实名";
                }
                Bll = null;
            }
        }
        private void DataBindeTable()
        {
            if (_hidUserId.Value != "")
            {
                if (_hidsRecId.Value != "")
                {
                    ViewState["Query"] = " and $$qId$$ =" + _hidsRecId.Value + "";
                    ViewState["Query"] += " and $$userId$$ =" + _hidUserId.Value + "";
                }
                QuestionBLL Bll = new QuestionBLL();
                DataSet dSet = Bll.GetOptionsMessage(ViewState["Query"].ToString(),"1");
                if (dSet.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < dSet.Tables[0].Rows.Count; i++)
                    {
                        DataRow dRow = dSet.Tables[0].Rows[i];
                        CreateTable(i, dRow);
                    }
                }
            }
        }
        private void CreateTable(int i, DataRow dRow)
        {
            int iLine = i;
            HtmlTableRow oRow = new HtmlTableRow();
            oRow.ID = "row_" + iLine.ToString();
            oRow.Attributes["class"] = "listrow2";

            HtmlTableCell oCellM = new HtmlTableCell();
            oCellM.Align = "left"; 
            oCellM.Attributes["class"] = "listrow2";
            oCellM.Attributes["width"] = "8%";
            oCellM.InnerText = (i + 1).ToString() + "、" + dRow["Qst_A2_30"].ToString(); 
            oRow.Cells.Add(oCellM);
            tbProduct.Rows.Add(oRow);
            HtmlTableRow oRow1 = new HtmlTableRow();
            QuestionBLL Bll = new QuestionBLL();
            DataSet dSetX = Bll.GetQuestion(dRow["Qst_A2_10"].ToString(), "1");
            string stype = "checkbox";
            string checkInfo = "";
            if (dSetX.Tables[0].Rows.Count > 0)
            {
                for (int j = 0; j < dSetX.Tables[0].Rows.Count; j++)
                {
                    DataRow dRowx = dSetX.Tables[0].Rows[j];
                    string iNum = Bll.GetAnswerMes(dRowx["Qst_A3_10"].ToString(), _hidUserId.Value);
                    checkInfo = (iNum != "") ? "checked" : "";
                    if (dRowx["Qst_A2_50"].ToString() == "0")
                    {
                        stype = "radio";
                    }
                    if (j == int.Parse(dRowx["Qst_A2_70"].ToString()))
                    { oRow1 = new HtmlTableRow(); }
                    HtmlTableCell oCellX = new HtmlTableCell();
                    oCellX.Align = "left";
                    oCellX.InnerHtml = "<nobr><input type=\"" + stype + "\"  disabled='disabled' " + checkInfo + ">" + dRowx["Qst_A3_40"].ToString() + "</nobr>";
                    oRow1.Cells.Add(oCellX);
                    tbProduct.Rows.Add(oRow1);
                }
            }
            if (dRow["Qst_A2_60"].ToString() == "1")
            {
                HtmlTableRow oRow2 = new HtmlTableRow();
                HtmlTableCell oCellY = new HtmlTableCell();
                oCellY.Align = "left";
                oCellY.Width = "14%";
                oCellY.InnerHtml = "<nobr>其他意见:" + dRow["Qst_A5_40"].ToString() + "</nobr>";
                oRow2.Cells.Add(oCellY);
                tbProduct.Rows.Add(oRow2);
            }
        }
    }
}
